package com.example.demo.exception;

import com.example.demo.common.AppResult;
import com.example.demo.common.ResultCode;

/**
 * @Author baekhyun
 **/
//自定义异常
public class ApplicationException extends RuntimeException{
    //自定义的异常描述
    private AppResult errorResult;

    //指定状态码，异常描述
    public ApplicationException(AppResult appResult) {
        //构造异常中的Message属性
        super(appResult.getMessage());
        //自定义的错误描述
        this.errorResult=appResult;
    }

    //自定义异常描述
    public ApplicationException(String message) {
        super(message);
        //根据异常描述构建返回对象
        this.errorResult=new AppResult(ResultCode.FAILED.getCode(),message);
    }

    //指定异常
    public ApplicationException(Throwable cause){
        super(cause);
    }

    //自定义异常描述，异常信息
    public ApplicationException(String message,Throwable cause){
        super(message,cause);
    }

    public AppResult getErrorResult() {
        return errorResult;
    }

    public void setErrorResult(AppResult errorResult) {
        this.errorResult = errorResult;
    }
}
